package com.leo.offer;

import java.util.Arrays;

/**
 * 调整数组顺序使奇数位于偶数前面
 * @author xuexiaolei
 * @version 2018年03月01日
 */
public class T14 {
    public static void reorderOddEven(int[] a){
        int i=0,j=a.length-1;
        while (i<j){
            while (i<j && (a[i]&1)==1){ i++; }
            while (i<j && (a[j]&1)==0){ j--; }
            if (i<j){
                int temp = a[i];
                a[i] = a[j];
                a[j] = temp;
            }
        }
    }

    public static void main(String[] args) {
        int[] a = new int[]{1,5,2,52,823,72,52,4,2,4};
        reorderOddEven(a);
        System.out.println(Arrays.toString(a));
    }
}
